<template>
	<el-container class="home-container">
		<!-- 头部区域 -->
		<el-header>
			<div>
				<img src="../assets/5BA64942-292D-4ee3-8EF1-25FAF625CB6C.png" alt=""/>
				<span>阳光招生系统</span>
			</div>
			
			<el-dropdown @command="setDialogInfo">
			        <span class="el-dropdown-link">
			          <span style="color: white;">
			            欢迎，
			            <span style="color: white;">{{ username }}</span>
			          </span>
			          <span style="color: white;">用户设置</span>
			          <i class="el-icon-arrow-down el-icon--right" style="color: white;font-size: 18px;"></i>
			        </span>
			        <el-dropdown-menu slot="dropdown" >
			          <el-dropdown-item command="changepwdvisible">修改密码</el-dropdown-item>
			          <el-dropdown-item command="logout">退出登录</el-dropdown-item>
			        </el-dropdown-menu>
			      </el-dropdown>
		</el-header>
		<!-- 页面主题区域 -->
		<el-container>
			<!-- 侧边栏 -->
			<el-aside :width="isCollapse ? '64px' : '200px'">
				<div class="toggle-button" @click="toggleCollapse">|||</div>
				<!-- 侧边栏菜单区域 -->
				<el-menu background-color="#333744" text-color="#fff" active-text-color="#409EFF" unique-opened
					:collapse="isCollapse" :collapse-transition="false" router :default-active="activePath">
					<!-- 一级菜单 -->
					<el-submenu :index="item.Id + ''" v-for="item in menulist" :key="item.Id">
						<!-- 一级菜单的模板区域 -->
						<template slot="title">
							<!-- 图标 -->
							<i :class="iconObj[item.Id]"></i>
							<!-- 文本 -->
							<span>{{item.Name}}</span>
						</template>

						<!-- 二级菜单 -->
						<el-menu-item :index="'/' + subItem.Path" v-for="subItem in menulist1" :key="subItem.Id"
							@click="saveNavState('/' + subItem.Path)" v-if="subItem.ParentId == item.Id">
							<template slot="title">
								<!-- 图标 -->
								<i class="el-icon-menu"></i>
								<!-- 文本 -->
								<span>{{subItem.Name}}</span>
							</template>
						</el-menu-item>
					</el-submenu>
					
				</el-menu>
			</el-aside>
			
			<!-- 右侧主题内容 -->
			<el-main>
				<!-- 路由占位符 -->
				<router-view></router-view>
			</el-main>
		</el-container>
		<!-- 修改密码 -->
		<el-dialog title="修改密码" :visible.sync="dialogFormVisible">
		  <el-form :model="form">
			  <el-form-item label="用户名" :label-width="formLabelWidth">
			    <el-input v-model="form.LoginName" autocomplete="off" disabled></el-input>
			  </el-form-item>
		    <el-form-item label="请输入原密码" :label-width="formLabelWidth">
		      <el-input v-model="form.psd" autocomplete="off"></el-input>
		    </el-form-item>
		    <el-form-item label="请输入修改密码" :label-width="formLabelWidth">
		      <el-input v-model="form.resetpsd" autocomplete="off"></el-input>
		    </el-form-item>
		  </el-form>
		  <div slot="footer" class="dialog-footer">
		    <el-button @click="dialogFormVisible = false">取 消</el-button>
		    <el-button type="primary" @click="onSubmit">确 定</el-button>
		  </div>
		</el-dialog>
	</el-container>


</template>

<script>
	export default {
		data() {
			return {
				//左侧菜单数据
				form:{
					LoginName:'',
					psd:'',
					resetpsd:''
				},
				menu:[],
				menulist: [],
				menulist1: [],
				iconObj: {
					'1': 'iconfont icon-user',
					'5': 'iconfont icon-tijikongjian',
					'16': 'iconfont icon-shangpin',
					'17': 'iconfont icon-danju',
					'19': 'iconfont icon-baobiao'
				},
				//是否折叠
				isCollapse: false,
				//被激活的链接地址
				activePath: '',
				username:'',
				dialogFormVisible:false,
				formLabelWidth:'110px'
			}
		},
		created() {
			this.getMenuList()
			this.activePath = window.sessionStorage.getItem('activePath')
		},
		methods: {
			async changepwdvisible(){
				// alert("修改密码")
				this.dialogFormVisible=true;	
			},
			async onSubmit() {
			        const {
			          data: res
			        } = await this.$http.get('/api/api/Home/UpadatePsw', {
			          params: {
			            LoginName: this.form.LoginName,
			            psd: this.form.psd,
			            resetpsd: this.form.resetpsd
			          }
			        });
					// console.log(res)
			        if (res.code != 0) {
			          return this.$message.error(res.msg);
			        }
			        this.$message.error(res.msg);
			        this.editpwdVisible = false;
			        this.logout();
			    } ,
			logout() {
				window.sessionStorage.clear();
				this.$router.push('/login')
			},
			getMenuList() {
				let s = parseInt(window.sessionStorage.getItem('token'));
				// console.log(s);
				let _this = this;
				this.$axios.post('/api/api/Home/GetMenu', {
					Id: s
				}).then(function(res) {
					// console.log(res);
					if (res.status == 200) {
						// console.log(res);
						_this.username=res.data.username;
						_this.form.LoginName=_this.username;
						_this.menulist = res.data.data;
						_this.menulist1 = res.data.datas;
					} else {
						
					}
				})
			},
			//点击按钮，切换菜单的折叠与展开
			toggleCollapse() {
				this.isCollapse = !this.isCollapse
			},
			//保存连接的激活状态
			saveNavState(activePath) {
				window.sessionStorage.setItem('activePath', activePath)
				this.activePath = activePath
			},
			// 下拉框选择，点击个人信息后调整到对应的函数执行
			      setDialogInfo(comItem) {
			        switch (comItem) {
			          case 'changepwdvisible':
			            this.changepwdvisible();
			            break;
			          case 'logout':
			            this.logout();
			            break;
			        }
			      },

		}
	}
</script>

<style Lang="less" scoped>
	.home-container {
		height: 100%;
	}
    .el-button{
		margin-right: 10px;
	}
	.el-header {
		background-color: #373d41;
		display: flex;
		justify-content: space-between;
		padding-left: 0;
		align-items: center;
		color: #fff;
		font-size: 20px;
		
	}
    .el-header div{
			display: flex;
			align-items: center;

			
		}
	.el-header span {
				margin-left: 10px;
				padding-bottom: 5px;
			} 
	.el-aside {
		background-color: #333744;

		.el-menu {
			border-right: none;
		}
	}

	.el-main {
		background-color: #EAEDF1;
	}

	.iconfont {
		margin: 10px;
	}

	.toggle-button {
		background-color: #4A5064;
		font-size: 10px;
		line-height: 24px;
		color: #fff;
		text-align: center;
		letter-spacing: 0.2em;
		cursor: pointer;
	}
</style>
